<?php


namespace app\api\model;

use think\Model;

/**
 * 新闻列表
 * Class NewsModel
 * @package app\api\model
 */
class NewsModel extends Model
{

    /**
     * 设置表名
     * @var string
     */
    protected $table = 'te_news';

    /**
     *
     * 新闻列表
     */
    public static function newsList($params){

        $where = [];
        #分类搜索
        if (isset($params['cate_id']) && $params['cate_id'] != ''){

            $where[] = ['cate_id','eq',$params['cate_id']];
        }
        #是否首页展示
        if (isset($params['is_index']) && $params['is_index'] == 'index'){

            $where[] = ['is_index','eq',1];
        }
        #分页
        $page = page($params);
        return self::where(['status'=>1,'is_deleted'=>0])
            ->where($where)
            ->field('id,title,logo,create_at')
            ->order('id desc')
            ->limit($page['page'],$page['page_size'])
            ->select();
    }

    /**
     *
     * 新闻信息
     */
    public static function newsInfo($id){

        $data = self::where(['id'=>$id])->field('id,title,imgs,content,create_at')->find();
        if ($data['imgs']){

            $data['imgs'] = explode('|',$data['imgs']);
        }
        return $data;
    }
}